<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>只能输入数字的文本框</title>
   <style>
   </style>
   <script>
      window.onload=function(){
	     var oTxt=document.getElementById("txt1");
		 
		 oTxt.onkeydown=function(ev){
		 var oEvent=ev||event;
		 //alert(oEvent.keyCode);
		 //0---48 9---57
		 if(oEvent.keyCode!=8&&(oEvent.keyCode<48||oEvent.keyCode>57)){
		    return false;
		   }
		 };
	  };
   </script>
</head>
<body>
  <input type="text" id="txt1"/>


</body>
</html>